﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrienDev;
using FrienDev.BusinessRules;

public partial class Controls_Club_ActivityList : System.Web.UI.UserControl
{
    private int m_PageSize=20;
    private int m_Count;
    protected void BindPagingData()
    {
        m_Count = ActivityRules.Instance.GetClubPagingActivityCount(ClubId);
        //显示Pager
        if (m_Count == 0)
        {
            this.Pager.Visible = false;
        }
        else
        {
            this.Pager.RecordCount = m_Count;
            m_PageSize = this.Pager.PageSize;
            this.Pager.Visible = true;
        }
        ActivityGrid.DataSource = ActivityRules.Instance.GetClubPagingActivity(ClubId, (this.Pager.CurrentPageIndex - 1) * m_PageSize, m_PageSize);
        ActivityGrid.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ClubRules.Instance.GetClubIsOpenByClubId(ClubId))
        {
            if (!IsPaging)
            {
                ActivityGrid.DataSource = ActivityRules.Instance.GetClubActivity(ClubId);
                //不显示Pager
                this.Pager.Visible = false;
                ActivityGrid.DataBind();

            }
            else
            {
                BindPagingData();
            }

        }
        else
        {
            if (!ClubRules.Instance.IsClubMemberByClubId(ClubId))
            {
                this.pn_Privacy.Visible = true;
                this.ActivityGrid.Visible = false;
            }
            else
            {
                if (!IsPaging)
                {
                    ActivityGrid.DataSource = ActivityRules.Instance.GetClubActivity(ClubId);
                    //不显示Pager
                    this.Pager.Visible = false;
                    ActivityGrid.DataBind();

                }
                else
                {
                    BindPagingData();
                }
            }
        }
        

    }

    protected void ActivityGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label temp_lbActivityState = e.Row.FindControl("lbl_ActivityState") as Label;
            Label temp_lblPostsCount = e.Row.FindControl("lbl_PostsCount") as Label;
            Label temp_txtBeginDateTime = e.Row.FindControl("txt_BeginDateTime") as Label;
            if (temp_lbActivityState.Text == "报名")
            {
                temp_lbActivityState.ForeColor = System.Drawing.Color.FromArgb(100,255,102,0);
                temp_lbActivityState.Font.Bold = true;
                temp_lblPostsCount.ForeColor = System.Drawing.Color.FromArgb(100, 255, 102, 0);
                temp_txtBeginDateTime.ForeColor = System.Drawing.Color.FromArgb(100, 255, 102, 0);
            }
            
        }
     }

    /// <summary>
    /// 是否过期
    /// </summary>
    public bool IsOutOfDate { get; set; }

    /// <summary>
    /// 是否好友
    /// </summary>
    public bool IsFriend { get; set; }

    /// <summary>
    /// 是否俱乐部活动
    /// </summary>
    public bool IsClub { get; set; }

    /// <summary>
    /// 是否分页
    /// </summary>
    public bool IsPaging { get; set; }

    /// <summary>
    /// 俱乐部ID
    /// </summary>
    public int ClubId
    {
        get
        {
            return GetQueryStringValue("clubId", 0);
        }
    }

    #region Protected Method
    protected int GetQueryStringValue(string QueryName, int nullValue)
    {

        if (string.IsNullOrEmpty(this.Page.Request.QueryString[QueryName]))
        {
            return nullValue;
        }
        return Convert.ToInt32(this.Page.Request.QueryString[QueryName]);
    }
    protected string GetQueryStringValue(string QueryName, string nullValue)
    {

        if (string.IsNullOrEmpty(this.Page.Request.QueryString[QueryName]))
        {
            return nullValue;
        }
        return this.Page.Request.QueryString[QueryName];
    }

    protected bool GetQueryStringValue(string QueryName, bool nullValue)
    {
        if (string.IsNullOrEmpty(this.Page.Request.QueryString[QueryName]))
        {
            return nullValue;
        }
        return Convert.ToBoolean(this.Page.Request.QueryString[QueryName]);
    }
    #endregion

}
